﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;


using Sogeti.VSExtention;

namespace Mskold.IterationManager
{
    /// <summary>
    /// Interaction logic for Settings.xaml
    /// </summary>
    public partial class SettingsDlg : Window
    {



        
        private SettingsViewModel vm;

        public SettingsDlg()
        {
            InitializeComponent();
        }

        public SettingsDlg(TeamExplorerIntergator te)
        {
            InitializeComponent(); 

            vm = new SettingsViewModel();
            vm.Load(te);

            this.DataContext = vm;
            
        }
        public SettingsDlg(IterationManagerConfig conf,  TeamExplorerIntergator te)
        {
            InitializeComponent();

            vm = new SettingsViewModel(conf);
            vm.Load(te);
            

            this.DataContext = vm;
        }
        
        private void cmdCancel_Click(object sender, RoutedEventArgs e)
        {
            Close();
        }

        private void cmdOk_Click(object sender, RoutedEventArgs e)
        {
            using (new WaitCursor(this))
            {
                vm.Config.Save();
                Close();

            }
        }

        private void cbo_SprintWI_Changed(object sender, SelectionChangedEventArgs e)
        {
            var bindingExpression = cboSprintStartField.GetBindingExpression(ComboBox.ItemsSourceProperty);
            bindingExpression.UpdateTarget();
            bindingExpression = cboSprintFinishField.GetBindingExpression(ComboBox.ItemsSourceProperty);
            bindingExpression.UpdateTarget();

        }
    }
}
